#include "Message.h"
#include "font.h"

#include <string>

#define CHAR_WIDTH 16.0

Message::Message() {
	/* Initialisation des matrices */
	sf::Vector2f matriceTemp[27] = {
		sf::Vector2f(528.0, 0.0),
		sf::Vector2f(544.0, 0.0),
		sf::Vector2f(560.0, 0.0),
		sf::Vector2f(576.0, 0.0),
		sf::Vector2f(592.0, 0.0),
		sf::Vector2f(608.0, 0.0),
		sf::Vector2f(624.0, 0.0),
		sf::Vector2f(640.0, 0.0),
		sf::Vector2f(656.0, 0.0),
		sf::Vector2f(672.0, 0.0),
		sf::Vector2f(688.0, 0.0),
		sf::Vector2f(704.0, 0.0),
		sf::Vector2f(720.0, 0.0),
		sf::Vector2f(736.0, 0.0),
		sf::Vector2f(752.0, 0.0),
		sf::Vector2f(768.0, 0.0),
		sf::Vector2f(784.0, 0.0),
		sf::Vector2f(800.0, 0.0),
		sf::Vector2f(816.0, 0.0),
		sf::Vector2f(832.0, 0.0),
		sf::Vector2f(848.0, 0.0),
		sf::Vector2f(864.0, 0.0),
		sf::Vector2f(880.0, 0.0),
		sf::Vector2f(896.0, 0.0),
		sf::Vector2f(912.0, 0.0),
		sf::Vector2f(928.0, 0.0),
		sf::Vector2f(16.0, 0.0)
	};
	memcpy(lettersMatrice, matriceTemp, sizeof(sf::Vector2f) * 27);

	std::string path = "../Img/font/full_font.png";

	if (!fontTexture.loadFromFile(path)) {
		printf("Erreur au chargement de la texture\n");
	}
}

void Message::drawYouWin(sf::RenderWindow& w) {
	position = sf::Vector2f(350.0, 300.0);
	sf::Vector2f posInter = position;

	sf::Sprite sprite[7];

	sprite[0].setTexture(fontTexture, true);
	sprite[0].setTextureRect(sf::IntRect(lettersMatrice[Y].x,
		lettersMatrice[Y].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[0].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[0].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[1].setTexture(fontTexture, true);
	sprite[1].setTextureRect(sf::IntRect(lettersMatrice[O].x,
		lettersMatrice[O].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[1].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[1].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[2].setTexture(fontTexture, true);
	sprite[2].setTextureRect(sf::IntRect(lettersMatrice[U].x,
		lettersMatrice[U].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[2].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[2].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 10.0;

	sprite[3].setTexture(fontTexture, true);
	sprite[3].setTextureRect(sf::IntRect(lettersMatrice[W].x,
		lettersMatrice[W].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[3].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[3].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[4].setTexture(fontTexture, true);
	sprite[4].setTextureRect(sf::IntRect(lettersMatrice[I].x,
		lettersMatrice[I].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[4].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[4].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[5].setTexture(fontTexture, true);
	sprite[5].setTextureRect(sf::IntRect(lettersMatrice[N].x,
		lettersMatrice[N].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[5].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[5].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 10.0;

	sprite[6].setTexture(fontTexture, true);
	sprite[6].setTextureRect(sf::IntRect(lettersMatrice[EXCL].x,
		lettersMatrice[EXCL].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[6].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[6].setPosition(posInter);


	int i;
	for (i = 0; i < 7; i++) {
		w.draw(sprite[i]);
	}
}

void Message::drawOtherWin(sf::RenderWindow& w) {
	position = sf::Vector2f(280.0, 300.0);
	sf::Vector2f posInter = position;

	sf::Sprite sprite[14];

	sprite[0].setTexture(fontTexture, true);
	sprite[0].setTextureRect(sf::IntRect(lettersMatrice[Y].x,
		lettersMatrice[Y].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[0].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[0].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[1].setTexture(fontTexture, true);
	sprite[1].setTextureRect(sf::IntRect(lettersMatrice[O].x,
		lettersMatrice[O].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[1].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[1].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[2].setTexture(fontTexture, true);
	sprite[2].setTextureRect(sf::IntRect(lettersMatrice[U].x,
		lettersMatrice[U].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[2].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[2].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[3].setTexture(fontTexture, true);
	sprite[3].setTextureRect(sf::IntRect(lettersMatrice[R].x,
		lettersMatrice[R].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[3].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[3].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 10.0;

	sprite[4].setTexture(fontTexture, true);
	sprite[4].setTextureRect(sf::IntRect(lettersMatrice[F].x,
		lettersMatrice[F].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[4].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[4].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[5].setTexture(fontTexture, true);
	sprite[5].setTextureRect(sf::IntRect(lettersMatrice[R].x,
		lettersMatrice[R].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[5].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[5].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[6].setTexture(fontTexture, true);
	sprite[6].setTextureRect(sf::IntRect(lettersMatrice[I].x,
		lettersMatrice[I].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[6].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[6].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[7].setTexture(fontTexture, true);
	sprite[7].setTextureRect(sf::IntRect(lettersMatrice[E].x,
		lettersMatrice[E].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[7].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[7].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[8].setTexture(fontTexture, true);
	sprite[8].setTextureRect(sf::IntRect(lettersMatrice[N].x,
		lettersMatrice[N].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[8].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[8].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[9].setTexture(fontTexture, true);
	sprite[9].setTextureRect(sf::IntRect(lettersMatrice[D].x,
		lettersMatrice[D].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[9].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[9].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 10.0;

	sprite[10].setTexture(fontTexture, true);
	sprite[10].setTextureRect(sf::IntRect(lettersMatrice[W].x,
		lettersMatrice[W].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[10].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[10].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[11].setTexture(fontTexture, true);
	sprite[11].setTextureRect(sf::IntRect(lettersMatrice[I].x,
		lettersMatrice[I].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[11].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[11].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[12].setTexture(fontTexture, true);
	sprite[12].setTextureRect(sf::IntRect(lettersMatrice[N].x,
		lettersMatrice[N].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[12].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[12].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 10.0;

	sprite[13].setTexture(fontTexture, true);
	sprite[13].setTextureRect(sf::IntRect(lettersMatrice[EXCL].x,
		lettersMatrice[EXCL].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[13].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[13].setPosition(posInter);


	int i;
	for (i = 0; i < 14; i++) {
		w.draw(sprite[i]);
	}
}

void Message::drawYouLoose(sf::RenderWindow& w) {
	position = sf::Vector2f(350.0, 300.0);
	sf::Vector2f posInter = position;

	sf::Sprite sprite[9];

	sprite[0].setTexture(fontTexture, true);
	sprite[0].setTextureRect(sf::IntRect(lettersMatrice[Y].x,
		lettersMatrice[Y].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[0].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[0].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[1].setTexture(fontTexture, true);
	sprite[1].setTextureRect(sf::IntRect(lettersMatrice[O].x,
		lettersMatrice[O].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[1].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[1].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[2].setTexture(fontTexture, true);
	sprite[2].setTextureRect(sf::IntRect(lettersMatrice[U].x,
		lettersMatrice[U].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[2].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[2].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 10.0;

	sprite[3].setTexture(fontTexture, true);
	sprite[3].setTextureRect(sf::IntRect(lettersMatrice[L].x,
		lettersMatrice[L].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[3].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[3].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[4].setTexture(fontTexture, true);
	sprite[4].setTextureRect(sf::IntRect(lettersMatrice[O].x,
		lettersMatrice[O].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[4].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[4].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[5].setTexture(fontTexture, true);
	sprite[5].setTextureRect(sf::IntRect(lettersMatrice[O].x,
		lettersMatrice[O].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[5].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[5].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[6].setTexture(fontTexture, true);
	sprite[6].setTextureRect(sf::IntRect(lettersMatrice[S].x,
		lettersMatrice[S].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[6].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[6].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 1.0;

	sprite[7].setTexture(fontTexture, true);
	sprite[7].setTextureRect(sf::IntRect(lettersMatrice[E].x,
		lettersMatrice[E].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[7].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[7].setPosition(posInter);

	posInter.x = posInter.x + CHAR_WIDTH + 10.0;

	sprite[8].setTexture(fontTexture, true);
	sprite[8].setTextureRect(sf::IntRect(lettersMatrice[EXCL].x,
		lettersMatrice[EXCL].y, CHAR_WIDTH, CHAR_WIDTH));
	sprite[8].setOrigin(CHAR_WIDTH/2, CHAR_WIDTH/2);
	sprite[8].setPosition(posInter);


	int i;
	for (i = 0; i < 9; i++) {
		w.draw(sprite[i]);
	}
}